package cn.yogehaoren.ack;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author WangNing
 * @since 1.0
 */
public class ACKConsumerMain {

    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("k8s-node2");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");

        Connection connection = connectionFactory.newConnection();

        Channel channel = connection.createChannel();

        MyACKConsumer consumer = new MyACKConsumer(channel);


        String exchangeName = "test_ack_exchange";
        String queueName = "ack_queue";
        String routingKey = "ack_save";
        channel.exchangeDeclare(exchangeName, "fanout", false, false, null);
        channel.queueDeclare(queueName, false, false, false, null);
        channel.queueBind(queueName, exchangeName, routingKey);

        // 1. autoAck 设置为false
        channel.basicConsume(queueName, false, consumer);


    }

}
